/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.commom.service.impl;

import co.yixiang.enums.BillDetailEnum;
import co.yixiang.enums.BillInfoEnum;
import co.yixiang.modules.commom.domain.YxProblem;
import co.yixiang.common.service.impl.BaseServiceImpl;
import co.yixiang.modules.user.domain.YxUserBill;
import co.yixiang.modules.user.vo.BillVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import co.yixiang.dozer.service.IGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import co.yixiang.modules.commom.service.YxProblemService;
import co.yixiang.modules.commom.service.dto.YxProblemDto;
import co.yixiang.modules.commom.service.dto.YxProblemQueryCriteria;
import co.yixiang.modules.commom.service.mapper.YxProblemMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;

import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author yhh
* @date 2020-09-16
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "yxProblem")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxProblemServiceImpl extends BaseServiceImpl<YxProblemMapper, YxProblem> implements YxProblemService {

    private final IGenerator generator;

    @Override
    //@Cacheable
    public Map<String, Object> queryAll(YxProblemQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<YxProblem> page = new PageInfo<>(queryAll(criteria));
        Map<String, Object> map = new LinkedHashMap<>(2);
        map.put("content", generator.convert(page.getList(), YxProblemDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }


    @Override
    //@Cacheable
    public List<YxProblem> queryAll(YxProblemQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(YxProblem.class, criteria));
    }


    @Override
    public void download(List<YxProblemDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (YxProblemDto yxProblem : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("反馈标题", yxProblem.getProblemTitele());
            map.put("解决内容", yxProblem.getProblemContent());
            map.put(" createTime",  yxProblem.getCreateTime());
            map.put("排序", yxProblem.getSort());
            map.put(" problemTypeId",  yxProblem.getProblemTypeId());
            map.put(" type",  yxProblem.getType());
            map.put("图片", yxProblem.getProblemImg());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }

    @Override
    public Page<YxProblem> findProblemList(int page, int limit) {
      Page page1=new Page(page,limit);
      return this.baseMapper.selectAllByPage(page1);
    }

}
